package com.chen.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;


@Controller
public class LoginController {
   @GetMapping("/login")
    public String loginPage(){
       //在controller中获取 Authentication对象
       SecurityContext securityContext = SecurityContextHolder.getContext();
       Authentication authentication = securityContext.getAuthentication();
       System.out.println("getPrincipal= " + authentication.getPrincipal());
       System.out.println("getCredentials = " + authentication.getCredentials());
       System.out.println("getAuthorities = " + authentication.getAuthorities());
       return "login";
   }

}
